using System.Data;
using Agile.Common;
using GeneratorCustomization;

// WARNING: This file has been generated. Any manual changes must be made within preserved regions or they will be lost.

//===============================================================================
//
// ExcludedTableColumnCollection
//
// PURPOSE: 
// 
//
// NOTES: 
// 
//
//===============================================================================
//
// Copyright (C) 2003 Wallis Software Solutions
// All rights reserved.
//
// THIS CODE AND INFORMATION IS PROVIDED 'AS IS' WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR
// FITNESS FOR A PARTICULAR PURPOSE.
//
//===============================================================================

namespace Descriptors.GeneratorCustomization
{
    /// <summary>
    /// ExcludedTableColumnCollection
    /// </summary>
    public class ExcludedTableColumnCollection : AgileCollection
    {
        #region Preserved Region - Developer Hand Written Code

        private static ExcludedTableColumnCollection _allExcludedColumns;

        /// <summary>
        /// Gets ALL of the columns listed in the excluded columns table.
        /// </summary>
        public static ExcludedTableColumnCollection All
        {
            get
            {
                if (_allExcludedColumns == null)
                    LoadExcludedColumns();
                return _allExcludedColumns;
            }
        }

        /// <summary>
        /// Load the excluded columns details from the xml file.
        /// </summary>
        private static void LoadExcludedColumns()
        {
            _allExcludedColumns = Build();
            DataRowCollection rows = GeneratorsData.GetDataRowsFor("ExcludedTableColumn");
            foreach (DataRow row in rows)
            {
                ExcludedTableColumn excluded = ExcludedTableColumn.Build(row["Database"].ToString(),
                                                                         row["TableName"].ToString(),
                                                                         row["Column"].ToString());
                _allExcludedColumns.Add(excluded);
            }
        }

        /// <summary>
        /// Get all filtered columns for a specific table name.
        /// </summary>
        /// <param name="tableName">Name of the table.</param>
        /// <returns></returns>
        public ExcludedTableColumnCollection FilteredBy(string tableName)
        {
            ExcludedTableColumnCollection filtered = Build();
            foreach (ExcludedTableColumn excluded in this)
            {
                if (excluded.Table.Equals(tableName))
                    filtered.Add(excluded);
            }
            return filtered;
        }

        /// <summary>
        /// Get all filtered columns for a specific table in a specific database.
        /// </summary>
        /// <param name="database">DatabaseName name.</param>
        /// <param name="tableName">Name of the table.</param>
        /// <returns></returns>
        public ExcludedTableColumnCollection FilteredBy(string database, string tableName)
        {
            ExcludedTableColumnCollection filtered = Build();
            foreach (ExcludedTableColumn excluded in this)
            {
                if (excluded.Table.Equals(tableName)
                    && excluded.Table.Equals(database))
                    filtered.Add(excluded);
            }
            return filtered;
        }


        /// <summary>
        /// Checks if the given ExcludedTableColumn is in the collection.
        /// </summary>
        /// <param name="checkForThisColumn">excludedTableColumn to look for in the collection.</param>
        /// <returns>True if the item is in the collection.</returns>
        public bool Contains(ExcludedTableColumn checkForThisColumn)
        {
            foreach (ExcludedTableColumn excludedColumn in this)
            {
                if (excludedColumn.ColumnName.ToLower().Equals(checkForThisColumn.ColumnName.ToLower())
                    && excludedColumn.Table.ToLower().Equals(checkForThisColumn.Table.ToLower())
                    && excludedColumn.Database.ToLower().Equals(checkForThisColumn.Database.ToLower()))
                    return true;
            }
            return false;
        }

        /// <summary>
        /// Checks if the given ExcludedTableColumn is in the collection.
        /// NOT case sensitive!
        /// </summary>
        /// <param name="name">The name of the column to look for in the collection.</param>
        /// <returns>True if the item is in the collection.</returns>
        public bool ContainsColumn(string name)
        {
            foreach (ExcludedTableColumn excludedColumn in this)
            {
                if (excludedColumn.ColumnName.ToLower().Equals(name.ToLower()))
                    return true;
            }
            return false;
        }

        #endregion // Preserved Region - Developer Hand Written Code

        #region Constructors and Factories

        /// <summary>
        /// Constructor
        /// </summary>
        internal ExcludedTableColumnCollection()
        {
        }

        /// <summary>
        /// Instantiate a new ExcludedTableColumnCollection
        /// </summary>
        public static ExcludedTableColumnCollection Build()
        {
            return new ExcludedTableColumnCollection();
        }

        #endregion

        #region Strongly Typed IList Implementations

        /// <summary>
        /// Returns the ExcludedTableColumn that is at the given index in the collection.
        /// </summary>
        public ExcludedTableColumn this[int index]
        {
            get { return InnerList[index] as ExcludedTableColumn; }
        }

        /// <summary>
        /// Add a new ExcludedTableColumn to the collection
        /// </summary>
        /// <param name="excludedTableColumn">excludedTableColumn to add to the collection.</param>
        public void Add(ExcludedTableColumn excludedTableColumn)
        {
            if (Contains(excludedTableColumn))
            {
                string message =
                    string.Format(
                        "Tried adding a ExcludedTableColumn ({0}; {1}; {2}) to the collection but it is already in it."
                        , excludedTableColumn.Database, excludedTableColumn.Table, excludedTableColumn.ColumnName);
                throw new AgileCommonException(message);
            }
            List.Add(excludedTableColumn);
        }

        /// <summary>
        /// Remove a ExcludedTableColumn from the collection
        /// </summary>
        /// <param name="excludedTableColumn">excludedTableColumn to remove from the collection.</param>
        public void Remove(ExcludedTableColumn excludedTableColumn)
        {
            InnerList.Remove(excludedTableColumn);
        }


        /// <summary>
        /// Searches for the specified ExcludedTableColumn and returns the zero-based index
        /// of the first occurrence within the section of the
        /// collection that starts at the
        /// specified index and contains the specified number of elements.
        /// </summary>
        /// <param name="excludedTableColumn">excludedTableColumn to get the index of from the collection.</param>
        /// <returns>The index of the item in the collection.</returns>
        public int IndexOf(ExcludedTableColumn excludedTableColumn)
        {
            return InnerList.IndexOf(excludedTableColumn);
        }

        /// <summary>
        /// Searches for the specified ExcludedTableColumn and returns the zero-based index
        /// of the first occurrence within the section of the
        /// collection that starts at the
        /// specified index and contains the specified number of elements.
        /// </summary>
        /// <param name="excludedTableColumn">excludedTableColumn to get the index of from the collection.</param>
        /// <param name="startIndex">The zero-based starting index of the search.</param>
        /// <returns>The index of the item in the collection.</returns>
        public int IndexOf(ExcludedTableColumn excludedTableColumn, int startIndex)
        {
            return InnerList.IndexOf(excludedTableColumn, startIndex);
        }

        /// <summary>
        /// Searches for the specified ExcludedTableColumn and returns the zero-based index
        /// of the first occurrence within the section of the
        /// collection that starts at the
        /// specified index and contains the specified number of elements.
        /// </summary>
        /// <param name="excludedTableColumn">excludedTableColumn to get the index of from the collection.</param>
        /// <param name="startIndex">The zero-based starting index of the search.</param>
        /// <param name="count">The number of elements in the section to search.</param>
        /// <returns>The index of the item in the collection.</returns>
        public int IndexOf(ExcludedTableColumn excludedTableColumn, int startIndex, int count)
        {
            return InnerList.IndexOf(excludedTableColumn, startIndex, count);
        }

        /// <summary>
        /// Inserts the ExcludedTableColumn into the collection at the specified index.
        /// </summary>
        /// <param name="index">The zero-based index at which value should be inserted.</param>
        /// <param name="excludedTableColumn">excludedTableColumn to insert into the collection.</param>
        public void Insert(int index, ExcludedTableColumn excludedTableColumn)
        {
            InnerList.Insert(index, excludedTableColumn);
        }

        /// <summary>
        /// Copies a range of elements from the collection of ExcludedTableColumn's to a compatible
        /// one-dimensional System.Array, starting at the specified index of the target array.
        /// </summary>
        /// <param name="excludedTableColumns">The one-dimensional System.Array that is the destination of the elements copied from the collection. The System.Array must have zero-based indexing.</param>
        /// <param name="index">The zero-based index at which copying begins.</param>
        public void CopyTo(ExcludedTableColumn[] excludedTableColumns, int index)
        {
            List.CopyTo(excludedTableColumns, index);
        }

        #endregion
    }
}